home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume23 / flex2.3 / part01 next >
Encoding:
Internet Message Format  |  1990-10-10  |  52.5 KB

  1. Subject:  v23i037:  Flex, a fast lex replacement, Part01/10
  2. Newsgroups: comp.sources.unix
  3. Approved: rsalz@uunet.UU.NET
  4. X-Checksum-Snefru: 6558ddc9 f629c61f f6e5e61e 440e54c7
  5.  
  6. Submitted-by: Vern Paxson <vern@cs.cornell.edu>
  7. Posting-number: Volume 23, Issue 37
  8. Archive-name: flex2.3/part01
  9.  
  10. This is flex release 2.3, at patchlevel 6.
  11.  
  12. Flex is a replacement for lex.
  13.  
  14. #! /bin/sh
  15. # This is a shell archive.  Remove anything before this line, then feed it
  16. # into a shell via "sh file" or similar.  To overwrite existing files,
  17. # type "sh file -c".
  18. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  19. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  20. # Contents:  PACKNOTES README MANIFEST MISC MISC/README gen.c libmain.c
  21. #   scan.l
  22. # Wrapped by rsalz@litchi.bbn.com on Wed Oct 10 13:23:58 1990
  23. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  24. echo If this archive is complete, you will see the following message:
  25. echo '          "shar: End of archive 1 (of 10)."'
  26. if test -f 'PACKNOTES' -a "${1}" != "-c" ; then 
  27.   echo shar: Will not clobber existing file \"'PACKNOTES'\"
  28. else
  29.   echo shar: Extracting \"'PACKNOTES'\" \(179 characters\)
  30.   sed "s/^X//" >'PACKNOTES' <<'END_OF_FILE'
  31. X# "flexdoc.1" was split into 2 parts; to create it, do
  32. X    cat flexdoc.1.0[1-9] >flexdoc.1
  33. X# "initscan.c" was split into 2 parts; to create it, do
  34. X    cat initscan.c.0[1-9] >initscan.c
  35. END_OF_FILE
  36.   if test 179 -ne `wc -c <'PACKNOTES'`; then
  37.     echo shar: \"'PACKNOTES'\" unpacked with wrong size!
  38.   fi
  39.   # end of 'PACKNOTES'
  40. fi
  41. if test -f 'README' -a "${1}" != "-c" ; then 
  42.   echo shar: Will not clobber existing file \"'README'\"
  43. else
  44.   echo shar: Extracting \"'README'\" \(1599 characters\)
  45.   sed "s/^X//" >'README' <<'END_OF_FILE'
  46. X// $Header: /usr/fsys/odin/a/vern/flex/RCS/README,v 2.8 90/05/26 17:31:27 vern Exp $
  47. X
  48. XThis is release 2.3 of flex - a full release.
  49. X
  50. XThe flex distribution consists of the following files:
  51. X
  52. X    README        This message
  53. X
  54. X    Makefile
  55. X    flexdef.h
  56. X    parse.y
  57. X    scan.l
  58. X    ccl.c
  59. X    dfa.c
  60. X    ecs.c        flex sources
  61. X    gen.c
  62. X    main.c
  63. X    misc.c
  64. X    nfa.c
  65. X    sym.c
  66. X    tblcmp.c
  67. X    yylex.c
  68. X
  69. X    libmain.c    flex library (-lfl) source
  70. X
  71. X    initscan.c    pre-flex'd version of scan.l
  72. X
  73. X    flex.skel    skeleton for generated scanners
  74. X
  75. X    flexdoc.1    full user documentation
  76. X    flex.1        reference documentation
  77. X
  78. X    Changes        Differences between this release and the previous one
  79. X
  80. X    COPYING        flex's copyright
  81. X
  82. X    MISC/        a directory containing miscellaneous porting-related
  83. X            notes (for Atari, MS-DOS, Turbo-C, and VMS)
  84. X
  85. X
  86. XDecide where you want to keep flex.skel (suggestion:  /usr/local/lib),
  87. Xbut don't move it there yet.  Edit "Makefile" and change the definition
  88. Xof SKELETON_FILE to reflect the full pathname of flex.skel.
  89. X
  90. XRead the "Porting considerations" note in the Makefile and make
  91. Xthe necessary changes.
  92. X
  93. XTo make flex for the first time, use:
  94. X
  95. X    make first_flex
  96. X
  97. Xwhich uses the pre-generated copy of the flex scanner (the scanner
  98. Xitself is written using flex).
  99. X
  100. XAssuming it builds successfully, you can test it using
  101. X
  102. X    make test
  103. X
  104. XThe "diff" should not show any differences.
  105. X
  106. XIf you're feeling adventurous, issue "make bigtest" and be prepared
  107. Xto wait a while.
  108. X
  109. XInstall flex using:
  110. X
  111. X    make install
  112. X
  113. X
  114. XPlease send problems and feedback to:
  115. X
  116. X    vern@cs.cornell.edu
  117. X    decvax!cornell!vern
  118. X
  119. X    Vern Paxson
  120. X    CS Department
  121. X    4126 Upson Hall
  122. X    Cornell University
  123. X    Ithaca, NY 14853-7501
  124. END_OF_FILE
  125.   if test 1599 -ne `wc -c <'README'`; then
  126.     echo shar: \"'README'\" unpacked with wrong size!
  127.   fi
  128.   # end of 'README'
  129. fi
  130. if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  131.   echo shar: Will not clobber existing file \"'MANIFEST'\"
  132. else
  133.   echo shar: Extracting \"'MANIFEST'\" \(1117 characters\)
  134.   sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
  135. X   File Name        Archive #    Description
  136. X----------------------------------------------------------
  137. XPACKNOTES                  1    Warnings about long lines, etc
  138. XREADME                     1    
  139. XMANIFEST                   1    
  140. XCOPYING                    2    
  141. XChanges                    9    
  142. XMISC                       1    
  143. XMISC/Atari.patches         4    
  144. XMISC/MSDOS.notes           9    
  145. XMISC/Makefile.VMS         10    
  146. XMISC/README                1    
  147. XMISC/Turbo-C.notes         9    
  148. XMakefile                  10    
  149. Xccl.c                     10    
  150. Xdfa.c                      6    
  151. Xecs.c                      9    
  152. Xflex.1                     4    
  153. Xflex.skel                  6    
  154. Xflexdef.h                  5    
  155. Xflexdoc.1.01               2    (part 1)
  156. Xflexdoc.1.02               8    (part 2)
  157. Xgen.c                      1    
  158. Xinitscan.c.01              3    (part 1)
  159. Xinitscan.c.02              7    (part 2)
  160. Xlibmain.c                  1    
  161. Xmain.c                     5    
  162. Xmisc.c                     8    
  163. Xnfa.c                      8    
  164. Xparse.y                    9    
  165. Xscan.l                     1    
  166. Xsym.c                      7    
  167. Xtblcmp.c                   7    
  168. Xyylex.c                    6    
  169. END_OF_FILE
  170.   if test 1117 -ne `wc -c <'MANIFEST'`; then
  171.     echo shar: \"'MANIFEST'\" unpacked with wrong size!
  172.   fi
  173.   # end of 'MANIFEST'
  174. fi
  175. if test ! -d 'MISC' ; then
  176.     echo shar: Creating directory \"'MISC'\"
  177.     mkdir 'MISC'
  178. fi
  179. if test -f 'MISC/README' -a "${1}" != "-c" ; then 
  180.   echo shar: Will not clobber existing file \"'MISC/README'\"
  181. else
  182.   echo shar: Extracting \"'MISC/README'\" \(520 characters\)
  183.   sed "s/^X//" >'MISC/README' <<'END_OF_FILE'
  184. XMiscellaneous flex stuff.  In here you'll find:
  185. X
  186. X  - a VMS makefile for flex
  187. X
  188. X  - out-of-date patches for flex on the Atari and for Minix,
  189. X    from Ronald Lamprecht (V61%DHDURZ1.BITNET@CUNYVM.CUNY.EDU,
  190. X    ...!unido!DHDURZ1.bitnet!V61, V61@DHDURZ1 (Bitnet));
  191. X
  192. X  - somewhat out-of-date notes on porting flex to MS-DOS, from
  193. X    Jeffrey R. Jones (jjones@angate.att.com);
  194. X
  195. X  - notes on porting flex to Turbo-C, from Frank Whaley (few@quad1.quad.com,
  196. X    uunet!ccicpg!quad1!few).
  197. X
  198. XUpdated versions of these will be welcome!
  199. END_OF_FILE
  200.   if test 520 -ne `wc -c <'MISC/README'`; then
  201.     echo shar: \"'MISC/README'\" unpacked with wrong size!
  202.   fi
  203.   # end of 'MISC/README'
  204. fi
  205. if test -f 'gen.c' -a "${1}" != "-c" ; then 
  206.   echo shar: Will not clobber existing file \"'gen.c'\"
  207. else
  208.   echo shar: Extracting \"'gen.c'\" \(31594 characters\)
  209.   sed "s/^X//" >'gen.c' <<'END_OF_FILE'
  210. X/* gen - actual generation (writing) of flex scanners */
  211. X
  212. X/*-
  213. X * Copyright (c) 1990 The Regents of the University of California.
  214. X * All rights reserved.
  215. X *
  216. X * This code is derived from software contributed to Berkeley by
  217. X * Vern Paxson.
  218. X * 
  219. X * The United States Government has rights in this work pursuant
  220. X * to contract no. DE-AC03-76SF00098 between the United States
  221. X * Department of Energy and the University of California.
  222. X *
  223. X * Redistribution and use in source and binary forms are permitted provided
  224. X * that: (1) source distributions retain this entire copyright notice and
  225. X * comment, and (2) distributions including binaries display the following
  226. X * acknowledgement:  ``This product includes software developed by the
  227. X * University of California, Berkeley and its contributors'' in the
  228. X * documentation or other materials provided with the distribution and in
  229. X * all advertising materials mentioning features or use of this software.
  230. X * Neither the name of the University nor the names of its contributors may
  231. X * be used to endorse or promote products derived from this software without
  232. X * specific prior written permission.
  233. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  234. X * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  235. X * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  236. X */
  237. X
  238. X#ifndef lint
  239. Xstatic char rcsid[] =
  240. X    "@(#) $Header: /usr/helios/u0/vern/flex/RCS/gen.c,v 2.10 90/08/29 12:11:13 vern Exp $ (LBL)";
  241. X#endif
  242. X
  243. X#include "flexdef.h"
  244. X
  245. X
  246. X/* declare functions that have forward references */
  247. X
  248. Xvoid gen_next_state PROTO((int));
  249. Xvoid genecs PROTO(());
  250. Xvoid indent_put2s PROTO((char [], char []));
  251. Xvoid indent_puts PROTO((char []));
  252. X
  253. X
  254. Xstatic int indent_level = 0; /* each level is 4 spaces */
  255. X
  256. X#define indent_up() (++indent_level)
  257. X#define indent_down() (--indent_level)
  258. X#define set_indent(indent_val) indent_level = indent_val
  259. X
  260. X/* *everything* is done in terms of arrays starting at 1, so provide
  261. X * a null entry for the zero element of all C arrays
  262. X */
  263. Xstatic char C_short_decl[] = "static const short int %s[%d] =\n    {   0,\n";
  264. Xstatic char C_long_decl[] = "static const long int %s[%d] =\n    {   0,\n";
  265. Xstatic char C_state_decl[] =
  266. X    "static const yy_state_type %s[%d] =\n    {   0,\n";
  267. X
  268. X
  269. X/* indent to the current level */
  270. X
  271. Xvoid do_indent()
  272. X
  273. X    {
  274. X    register int i = indent_level * 4;
  275. X
  276. X    while ( i >= 8 )
  277. X    {
  278. X    putchar( '\t' );
  279. X    i -= 8;
  280. X    }
  281. X    
  282. X    while ( i > 0 )
  283. X    {
  284. X    putchar( ' ' );
  285. X    --i;
  286. X    }
  287. X    }
  288. X
  289. X
  290. X/* generate the code to keep backtracking information */
  291. X
  292. Xvoid gen_backtracking()
  293. X
  294. X    {
  295. X    if ( reject || num_backtracking == 0 )
  296. X    return;
  297. X
  298. X    if ( fullspd )
  299. X    indent_puts( "if ( yy_current_state[-1].yy_nxt )" );
  300. X    else
  301. X    indent_puts( "if ( yy_accept[yy_current_state] )" );
  302. X
  303. X    indent_up();
  304. X    indent_puts( "{" );
  305. X    indent_puts( "yy_last_accepting_state = yy_current_state;" );
  306. X    indent_puts( "yy_last_accepting_cpos = yy_cp;" );
  307. X    indent_puts( "}" );
  308. X    indent_down();
  309. X    }
  310. X
  311. X
  312. X/* generate the code to perform the backtrack */
  313. X
  314. Xvoid gen_bt_action()
  315. X
  316. X    {
  317. X    if ( reject || num_backtracking == 0 )
  318. X    return;
  319. X
  320. X    set_indent( 3 );
  321. X
  322. X    indent_puts( "case 0: /* must backtrack */" );
  323. X    indent_puts( "/* undo the effects of YY_DO_BEFORE_ACTION */" );
  324. X    indent_puts( "*yy_cp = yy_hold_char;" );
  325. X
  326. X    if ( fullspd || fulltbl )
  327. X    indent_puts( "yy_cp = yy_last_accepting_cpos + 1;" );
  328. X    else
  329. X    /* backtracking info for compressed tables is taken \after/
  330. X     * yy_cp has been incremented for the next state
  331. X     */
  332. X    indent_puts( "yy_cp = yy_last_accepting_cpos;" );
  333. X
  334. X    indent_puts( "yy_current_state = yy_last_accepting_state;" );
  335. X    indent_puts( "goto yy_find_action;" );
  336. X    putchar( '\n' );
  337. X
  338. X    set_indent( 0 );
  339. X    }
  340. X
  341. X
  342. X/* genctbl - generates full speed compressed transition table
  343. X *
  344. X * synopsis
  345. X *     genctbl();
  346. X */
  347. X
  348. Xvoid genctbl()
  349. X
  350. X    {
  351. X    register int i;
  352. X    int end_of_buffer_action = num_rules + 1;
  353. X
  354. X    /* table of verify for transition and offset to next state */
  355. X    printf( "static const struct yy_trans_info yy_transition[%d] =\n",
  356. X        tblend + numecs + 1 );
  357. X    printf( "    {\n" );
  358. X    
  359. X    /* We want the transition to be represented as the offset to the
  360. X     * next state, not the actual state number, which is what it currently is.
  361. X     * The offset is base[nxt[i]] - base[chk[i]].  That's just the
  362. X     * difference between the starting points of the two involved states
  363. X     * (to - from).
  364. X     *
  365. X     * first, though, we need to find some way to put in our end-of-buffer
  366. X     * flags and states.  We do this by making a state with absolutely no
  367. X     * transitions.  We put it at the end of the table.
  368. X     */
  369. X    /* at this point, we're guaranteed that there's enough room in nxt[]
  370. X     * and chk[] to hold tblend + numecs entries.  We need just two slots.
  371. X     * One for the action and one for the end-of-buffer transition.  We
  372. X     * now *assume* that we're guaranteed the only character we'll try to
  373. X     * index this nxt/chk pair with is EOB, i.e., 0, so we don't have to
  374. X     * make sure there's room for jam entries for other characters.
  375. X     */
  376. X
  377. X    base[lastdfa + 1] = tblend + 2;
  378. X    nxt[tblend + 1] = end_of_buffer_action;
  379. X    chk[tblend + 1] = numecs + 1;
  380. X    chk[tblend + 2] = 1; /* anything but EOB */
  381. X    nxt[tblend + 2] = 0; /* so that "make test" won't show arb. differences */
  382. X
  383. X    /* make sure every state has a end-of-buffer transition and an action # */
  384. X    for ( i = 0; i <= lastdfa; ++i )
  385. X    {
  386. X    register int anum = dfaacc[i].dfaacc_state;
  387. X
  388. X    chk[base[i]] = EOB_POSITION;
  389. X    chk[base[i] - 1] = ACTION_POSITION;
  390. X    nxt[base[i] - 1] = anum;    /* action number */
  391. X    }
  392. X
  393. X    for ( i = 0; i <= tblend; ++i )
  394. X    {
  395. X    if ( chk[i] == EOB_POSITION )
  396. X        transition_struct_out( 0, base[lastdfa + 1] - i );
  397. X
  398. X    else if ( chk[i] == ACTION_POSITION )
  399. X        transition_struct_out( 0, nxt[i] );
  400. X
  401. X    else if ( chk[i] > numecs || chk[i] == 0 )
  402. X        transition_struct_out( 0, 0 );        /* unused slot */
  403. X
  404. X    else    /* verify, transition */
  405. X        transition_struct_out( chk[i], base[nxt[i]] - (i - chk[i]) );
  406. X    }
  407. X
  408. X
  409. X    /* here's the final, end-of-buffer state */
  410. X    transition_struct_out( chk[tblend + 1], nxt[tblend + 1] );
  411. X    transition_struct_out( chk[tblend + 2], nxt[tblend + 2] );
  412. X
  413. X    printf( "    };\n" );
  414. X    printf( "\n" );
  415. X
  416. X    /* table of pointers to start states */
  417. X    printf( "static const struct yy_trans_info *yy_start_state_list[%d] =\n",
  418. X        lastsc * 2 + 1 );
  419. X    printf( "    {\n" );
  420. X
  421. X    for ( i = 0; i <= lastsc * 2; ++i )
  422. X    printf( "    &yy_transition[%d],\n", base[i] );
  423. X
  424. X    dataend();
  425. X
  426. X    if ( useecs )
  427. X    genecs();
  428. X    }
  429. X
  430. X
  431. X/* generate equivalence-class tables */
  432. X
  433. Xvoid genecs()
  434. X
  435. X    {
  436. X    register int i, j;
  437. X    static char C_char_decl[] = "static const %s %s[%d] =\n    {   0,\n";
  438. X    int numrows;
  439. X    Char clower();
  440. X
  441. X    if ( numecs < csize )
  442. X    printf( C_char_decl, "YY_CHAR", "yy_ec", csize );
  443. X    else
  444. X    printf( C_char_decl, "short", "yy_ec", csize );
  445. X
  446. X    for ( i = 1; i < csize; ++i )
  447. X    {
  448. X    if ( caseins && (i >= 'A') && (i <= 'Z') )
  449. X        ecgroup[i] = ecgroup[clower( i )];
  450. X
  451. X    ecgroup[i] = abs( ecgroup[i] );
  452. X    mkdata( ecgroup[i] );
  453. X    }
  454. X
  455. X    dataend();
  456. X
  457. X    if ( trace )
  458. X    {
  459. X    char *readable_form();
  460. X
  461. X    fputs( "\n\nEquivalence Classes:\n\n", stderr );
  462. X
  463. X    numrows = csize / 8;
  464. X
  465. X    for ( j = 0; j < numrows; ++j )
  466. X        {
  467. X        for ( i = j; i < csize; i = i + numrows )
  468. X        {
  469. X        fprintf( stderr, "%4s = %-2d", readable_form( i ), ecgroup[i] );
  470. X
  471. X        putc( ' ', stderr );
  472. X        }
  473. X
  474. X        putc( '\n', stderr );
  475. X        }
  476. X    }
  477. X    }
  478. X
  479. X
  480. X/* generate the code to find the action number */
  481. X
  482. Xvoid gen_find_action()
  483. X
  484. X    {
  485. X    if ( fullspd )
  486. X    indent_puts( "yy_act = yy_current_state[-1].yy_nxt;" );
  487. X
  488. X    else if ( fulltbl )
  489. X    indent_puts( "yy_act = yy_accept[yy_current_state];" );
  490. X
  491. X    else if ( reject )
  492. X    {
  493. X    indent_puts( "yy_current_state = *--yy_state_ptr;" );
  494. X    indent_puts( "yy_lp = yy_accept[yy_current_state];" );
  495. X
  496. X    puts( "find_rule: /* we branch to this label when backtracking */" );
  497. X
  498. X    indent_puts( "for ( ; ; ) /* until we find what rule we matched */" );
  499. X
  500. X    indent_up();
  501. X
  502. X    indent_puts( "{" );
  503. X
  504. X    indent_puts( "if ( yy_lp && yy_lp < yy_accept[yy_current_state + 1] )" );
  505. X    indent_up();
  506. X    indent_puts( "{" );
  507. X    indent_puts( "yy_act = yy_acclist[yy_lp];" );
  508. X
  509. X    if ( variable_trailing_context_rules )
  510. X        {
  511. X        indent_puts( "if ( yy_act & YY_TRAILING_HEAD_MASK ||" );
  512. X        indent_puts( "     yy_looking_for_trail_begin )" );
  513. X        indent_up();
  514. X        indent_puts( "{" );
  515. X
  516. X        indent_puts( "if ( yy_act == yy_looking_for_trail_begin )" );
  517. X        indent_up();
  518. X        indent_puts( "{" );
  519. X        indent_puts( "yy_looking_for_trail_begin = 0;" );
  520. X        indent_puts( "yy_act &= ~YY_TRAILING_HEAD_MASK;" );
  521. X        indent_puts( "break;" );
  522. X        indent_puts( "}" );
  523. X        indent_down();
  524. X
  525. X        indent_puts( "}" );
  526. X        indent_down();
  527. X
  528. X        indent_puts( "else if ( yy_act & YY_TRAILING_MASK )" );
  529. X        indent_up();
  530. X        indent_puts( "{" );
  531. X        indent_puts(
  532. X        "yy_looking_for_trail_begin = yy_act & ~YY_TRAILING_MASK;" );
  533. X        indent_puts(
  534. X        "yy_looking_for_trail_begin |= YY_TRAILING_HEAD_MASK;" );
  535. X
  536. X        if ( real_reject )
  537. X        {
  538. X        /* remember matched text in case we back up due to REJECT */
  539. X        indent_puts( "yy_full_match = yy_cp;" );
  540. X        indent_puts( "yy_full_state = yy_state_ptr;" );
  541. X        indent_puts( "yy_full_lp = yy_lp;" );
  542. X        }
  543. X
  544. X        indent_puts( "}" );
  545. X        indent_down();
  546. X
  547. X        indent_puts( "else" );
  548. X        indent_up();
  549. X        indent_puts( "{" );
  550. X        indent_puts( "yy_full_match = yy_cp;" );
  551. X        indent_puts( "yy_full_state = yy_state_ptr;" );
  552. X        indent_puts( "yy_full_lp = yy_lp;" );
  553. X        indent_puts( "break;" );
  554. X        indent_puts( "}" );
  555. X        indent_down();
  556. X
  557. X        indent_puts( "++yy_lp;" );
  558. X        indent_puts( "goto find_rule;" );
  559. X        }
  560. X
  561. X    else
  562. X        {
  563. X        /* remember matched text in case we back up due to trailing context
  564. X         * plus REJECT
  565. X         */
  566. X        indent_up();
  567. X        indent_puts( "{" );
  568. X        indent_puts( "yy_full_match = yy_cp;" );
  569. X        indent_puts( "break;" );
  570. X        indent_puts( "}" );
  571. X        indent_down();
  572. X        }
  573. X
  574. X    indent_puts( "}" );
  575. X    indent_down();
  576. X
  577. X    indent_puts( "--yy_cp;" );
  578. X
  579. X    /* we could consolidate the following two lines with those at
  580. X     * the beginning, but at the cost of complaints that we're
  581. X     * branching inside a loop
  582. X     */
  583. X    indent_puts( "yy_current_state = *--yy_state_ptr;" );
  584. X    indent_puts( "yy_lp = yy_accept[yy_current_state];" );
  585. X
  586. X    indent_puts( "}" );
  587. X
  588. X    indent_down();
  589. X    }
  590. X
  591. X    else
  592. X    /* compressed */
  593. X    indent_puts( "yy_act = yy_accept[yy_current_state];" );
  594. X    }
  595. X
  596. X
  597. X/* genftbl - generates full transition table
  598. X *
  599. X * synopsis
  600. X *     genftbl();
  601. X */
  602. X
  603. Xvoid genftbl()
  604. X
  605. X    {
  606. X    register int i;
  607. X    int end_of_buffer_action = num_rules + 1;
  608. X
  609. X    printf( C_short_decl, "yy_accept", lastdfa + 1 );
  610. X
  611. X
  612. X    dfaacc[end_of_buffer_state].dfaacc_state = end_of_buffer_action;
  613. X
  614. X    for ( i = 1; i <= lastdfa; ++i )
  615. X    {
  616. X    register int anum = dfaacc[i].dfaacc_state;
  617. X
  618. X    mkdata( anum );
  619. X
  620. X    if ( trace && anum )
  621. X        fprintf( stderr, "state # %d accepts: [%d]\n", i, anum );
  622. X    }
  623. X
  624. X    dataend();
  625. X
  626. X    if ( useecs )
  627. X    genecs();
  628. X
  629. X    /* don't have to dump the actual full table entries - they were created
  630. X     * on-the-fly
  631. X     */
  632. X    }
  633. X
  634. X
  635. X/* generate the code to find the next compressed-table state */
  636. X
  637. Xvoid gen_next_compressed_state( char_map )
  638. Xchar *char_map;
  639. X
  640. X    {
  641. X    indent_put2s( "register YY_CHAR yy_c = %s;", char_map );
  642. X
  643. X    /* save the backtracking info \before/ computing the next state
  644. X     * because we always compute one more state than needed - we
  645. X     * always proceed until we reach a jam state
  646. X     */
  647. X    gen_backtracking();
  648. X
  649. X    indent_puts(
  650. X    "while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )" );
  651. X    indent_up();
  652. X    indent_puts( "{" );
  653. X    indent_puts( "yy_current_state = yy_def[yy_current_state];" );
  654. X
  655. X    if ( usemecs )
  656. X    {
  657. X    /* we've arrange it so that templates are never chained
  658. X     * to one another.  This means we can afford make a
  659. X     * very simple test to see if we need to convert to
  660. X     * yy_c's meta-equivalence class without worrying
  661. X     * about erroneously looking up the meta-equivalence
  662. X     * class twice
  663. X     */
  664. X    do_indent();
  665. X    /* lastdfa + 2 is the beginning of the templates */
  666. X    printf( "if ( yy_current_state >= %d )\n", lastdfa + 2 );
  667. X
  668. X    indent_up();
  669. X    indent_puts( "yy_c = yy_meta[yy_c];" );
  670. X    indent_down();
  671. X    }
  672. X
  673. X    indent_puts( "}" );
  674. X    indent_down();
  675. X
  676. X    indent_puts(
  677. X    "yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];" );
  678. X    }
  679. X
  680. X
  681. X/* generate the code to find the next match */
  682. X
  683. Xvoid gen_next_match()
  684. X
  685. X    {
  686. X    /* NOTE - changes in here should be reflected in gen_next_state() and
  687. X     * gen_NUL_trans()
  688. X     */
  689. X    char *char_map = useecs ? "yy_ec[*yy_cp]" : "*yy_cp";
  690. X    char *char_map_2 = useecs ? "yy_ec[*++yy_cp]" : "*++yy_cp";
  691. X    
  692. X    if ( fulltbl )
  693. X    {
  694. X    indent_put2s(
  695. X        "while ( (yy_current_state = yy_nxt[yy_current_state][%s]) > 0 )",
  696. X        char_map );
  697. X
  698. X    indent_up();
  699. X
  700. X    if ( num_backtracking > 0 )
  701. X        {
  702. X        indent_puts( "{" );
  703. X        gen_backtracking();
  704. X        putchar( '\n' );
  705. X        }
  706. X
  707. X    indent_puts( "++yy_cp;" );
  708. X
  709. X    if ( num_backtracking > 0 )
  710. X        indent_puts( "}" );
  711. X
  712. X    indent_down();
  713. X
  714. X    putchar( '\n' );
  715. X    indent_puts( "yy_current_state = -yy_current_state;" );
  716. X    }
  717. X
  718. X    else if ( fullspd )
  719. X    {
  720. X    indent_puts( "{" );
  721. X    indent_puts( "register const struct yy_trans_info *yy_trans_info;\n" );
  722. X    indent_puts( "register YY_CHAR yy_c;\n" );
  723. X    indent_put2s( "for ( yy_c = %s;", char_map );
  724. X    indent_puts(
  725. X    "      (yy_trans_info = &yy_current_state[yy_c])->yy_verify == yy_c;" );
  726. X    indent_put2s( "      yy_c = %s )", char_map_2 );
  727. X
  728. X    indent_up();
  729. X
  730. X    if ( num_backtracking > 0 )
  731. X        indent_puts( "{" );
  732. X
  733. X    indent_puts( "yy_current_state += yy_trans_info->yy_nxt;" );
  734. X
  735. X    if ( num_backtracking > 0 )
  736. X        {
  737. X        putchar( '\n' );
  738. X        gen_backtracking();
  739. X        indent_puts( "}" );
  740. X        }
  741. X
  742. X    indent_down();
  743. X    indent_puts( "}" );
  744. X    }
  745. X
  746. X    else
  747. X    { /* compressed */
  748. X    indent_puts( "do" );
  749. X
  750. X    indent_up();
  751. X    indent_puts( "{" );
  752. X
  753. X    gen_next_state( false );
  754. X
  755. X    indent_puts( "++yy_cp;" );
  756. X
  757. X    indent_puts( "}" );
  758. X    indent_down();
  759. X
  760. X    do_indent();
  761. X
  762. X    if ( interactive )
  763. X        printf( "while ( yy_base[yy_current_state] != %d );\n", jambase );
  764. X    else
  765. X        printf( "while ( yy_current_state != %d );\n", jamstate );
  766. X
  767. X    if ( ! reject && ! interactive )
  768. X        {
  769. X        /* do the guaranteed-needed backtrack to figure out the match */
  770. X        indent_puts( "yy_cp = yy_last_accepting_cpos;" );
  771. X        indent_puts( "yy_current_state = yy_last_accepting_state;" );
  772. X        }
  773. X    }
  774. X    }
  775. X
  776. X
  777. X/* generate the code to find the next state */
  778. X
  779. Xvoid gen_next_state( worry_about_NULs )
  780. Xint worry_about_NULs;
  781. X
  782. X    { /* NOTE - changes in here should be reflected in get_next_match() */
  783. X    char char_map[256];
  784. X
  785. X    if ( worry_about_NULs && ! nultrans )
  786. X    {
  787. X    if ( useecs )
  788. X        (void) sprintf( char_map, "(*yy_cp ? yy_ec[*yy_cp] : %d)", NUL_ec );
  789. X    else
  790. X        (void) sprintf( char_map, "(*yy_cp ? *yy_cp : %d)", NUL_ec );
  791. X    }
  792. X
  793. X    else
  794. X    (void) strcpy( char_map, useecs ? "yy_ec[*yy_cp]" : "*yy_cp" );
  795. X
  796. X    if ( worry_about_NULs && nultrans )
  797. X    {
  798. X    if ( ! fulltbl && ! fullspd )
  799. X        /* compressed tables backtrack *before* they match */
  800. X        gen_backtracking();
  801. X
  802. X    indent_puts( "if ( *yy_cp )" );
  803. X    indent_up();
  804. X    indent_puts( "{" );
  805. X    }
  806. X   
  807. X    if ( fulltbl )
  808. X    indent_put2s( "yy_current_state = yy_nxt[yy_current_state][%s];", 
  809. X        char_map );
  810. X    
  811. X    else if ( fullspd )
  812. X    indent_put2s( "yy_current_state += yy_current_state[%s].yy_nxt;",
  813. X            char_map );
  814. X
  815. X    else
  816. X    gen_next_compressed_state( char_map );
  817. X
  818. X    if ( worry_about_NULs && nultrans )
  819. X    {
  820. X    indent_puts( "}" );
  821. X    indent_down();
  822. X    indent_puts( "else" );
  823. X    indent_up();
  824. X    indent_puts( "yy_current_state = yy_NUL_trans[yy_current_state];" );
  825. X    indent_down();
  826. X    }
  827. X    
  828. X    if ( fullspd || fulltbl )
  829. X    gen_backtracking();
  830. X
  831. X    if ( reject )
  832. X    indent_puts( "*yy_state_ptr++ = yy_current_state;" );
  833. X    }
  834. X
  835. X
  836. X/* generate the code to make a NUL transition */
  837. X
  838. Xvoid gen_NUL_trans()
  839. X
  840. X    { /* NOTE - changes in here should be reflected in get_next_match() */
  841. X    int need_backtracking = (num_backtracking > 0 && ! reject);
  842. X
  843. X    if ( need_backtracking )
  844. X    /* we'll need yy_cp lying around for the gen_backtracking() */
  845. X    indent_puts( "register YY_CHAR *yy_cp = yy_c_buf_p;" );
  846. X
  847. X    putchar( '\n' );
  848. X
  849. X    if ( nultrans )
  850. X    {
  851. X    indent_puts( "yy_current_state = yy_NUL_trans[yy_current_state];" );
  852. X    indent_puts( "yy_is_jam = (yy_current_state == 0);" );
  853. X    }
  854. X
  855. X    else if ( fulltbl )
  856. X    {
  857. X    do_indent();
  858. X    printf( "yy_current_state = yy_nxt[yy_current_state][%d];\n",
  859. X        NUL_ec );
  860. X    indent_puts( "yy_is_jam = (yy_current_state <= 0);" );
  861. X    }
  862. X
  863. X    else if ( fullspd )
  864. X    {
  865. X    do_indent();
  866. X    printf( "register int yy_c = %d;\n", NUL_ec );
  867. X
  868. X    indent_puts(
  869. X        "register const struct yy_trans_info *yy_trans_info;\n" );
  870. X    indent_puts( "yy_trans_info = &yy_current_state[yy_c];" );
  871. X    indent_puts( "yy_current_state += yy_trans_info->yy_nxt;" );
  872. X
  873. X    indent_puts( "yy_is_jam = (yy_trans_info->yy_verify != yy_c);" );
  874. X    }
  875. X
  876. X    else
  877. X    {
  878. X    char NUL_ec_str[20];
  879. X
  880. X    (void) sprintf( NUL_ec_str, "%d", NUL_ec );
  881. X    gen_next_compressed_state( NUL_ec_str );
  882. X
  883. X    if ( reject )
  884. X        indent_puts( "*yy_state_ptr++ = yy_current_state;" );
  885. X
  886. X    do_indent();
  887. X
  888. X    if ( interactive )
  889. X        printf( "yy_is_jam = (yy_base[yy_current_state] == %d);\n",
  890. X            jambase );
  891. X    else
  892. X        printf( "yy_is_jam = (yy_current_state == %d);\n", jamstate );
  893. X    }
  894. X
  895. X    /* if we've entered an accepting state, backtrack; note that
  896. X     * compressed tables have *already* done such backtracking, so
  897. X     * we needn't bother with it again
  898. X     */
  899. X    if ( need_backtracking && (fullspd || fulltbl) )
  900. X    {
  901. X    putchar( '\n' );
  902. X    indent_puts( "if ( ! yy_is_jam )" );
  903. X    indent_up();
  904. X    indent_puts( "{" );
  905. X    gen_backtracking();
  906. X    indent_puts( "}" );
  907. X    indent_down();
  908. X    }
  909. X    }
  910. X
  911. X
  912. X/* generate the code to find the start state */
  913. X
  914. Xvoid gen_start_state()
  915. X
  916. X    {
  917. X    if ( fullspd )
  918. X    indent_put2s( "yy_current_state = yy_start_state_list[yy_start%s];",
  919. X        bol_needed ? " + (yy_bp[-1] == '\\n' ? 1 : 0)" : "" );
  920. X
  921. X    else
  922. X    {
  923. X    indent_puts( "yy_current_state = yy_start;" );
  924. X
  925. X    if ( bol_needed )
  926. X        {
  927. X        indent_puts( "if ( yy_bp[-1] == '\\n' )" );
  928. X        indent_up();
  929. X        indent_puts( "++yy_current_state;" );
  930. X        indent_down();
  931. X        }
  932. X
  933. X    if ( reject )
  934. X        {
  935. X        /* set up for storing up states */
  936. X        indent_puts( "yy_state_ptr = yy_state_buf;" );
  937. X        indent_puts( "*yy_state_ptr++ = yy_current_state;" );
  938. X        }
  939. X    }
  940. X    }
  941. X
  942. X
  943. X/* gentabs - generate data statements for the transition tables
  944. X *
  945. X * synopsis
  946. X *    gentabs();
  947. X */
  948. X
  949. Xvoid gentabs()
  950. X
  951. X    {
  952. X    int i, j, k, *accset, nacc, *acc_array, total_states;
  953. X    int end_of_buffer_action = num_rules + 1;
  954. X
  955. X    /* *everything* is done in terms of arrays starting at 1, so provide
  956. X     * a null entry for the zero element of all C arrays
  957. X     */
  958. X    static char C_char_decl[] =
  959. X    "static const YY_CHAR %s[%d] =\n    {   0,\n";
  960. X
  961. X    acc_array = allocate_integer_array( current_max_dfas );
  962. X    nummt = 0;
  963. X
  964. X    /* the compressed table format jams by entering the "jam state",
  965. X     * losing information about the previous state in the process.
  966. X     * In order to recover the previous state, we effectively need
  967. X     * to keep backtracking information.
  968. X     */
  969. X    ++num_backtracking;
  970. X
  971. X    if ( reject )
  972. X    {
  973. X    /* write out accepting list and pointer list
  974. X     *
  975. X     * first we generate the "yy_acclist" array.  In the process, we compute
  976. X     * the indices that will go into the "yy_accept" array, and save the
  977. X     * indices in the dfaacc array
  978. X     */
  979. X    int EOB_accepting_list[2];
  980. X
  981. X    /* set up accepting structures for the End Of Buffer state */
  982. X    EOB_accepting_list[0] = 0;
  983. X    EOB_accepting_list[1] = end_of_buffer_action;
  984. X    accsiz[end_of_buffer_state] = 1;
  985. X    dfaacc[end_of_buffer_state].dfaacc_set = EOB_accepting_list;
  986. X
  987. X    printf( C_short_decl, "yy_acclist", max( numas, 1 ) + 1 );
  988. X
  989. X    j = 1;    /* index into "yy_acclist" array */
  990. X
  991. X    for ( i = 1; i <= lastdfa; ++i )
  992. X        {
  993. X        acc_array[i] = j;
  994. X
  995. X        if ( accsiz[i] != 0 )
  996. X        {
  997. X        accset = dfaacc[i].dfaacc_set;
  998. X        nacc = accsiz[i];
  999. X
  1000. X        if ( trace )
  1001. X            fprintf( stderr, "state # %d accepts: ", i );
  1002. X
  1003. X        for ( k = 1; k <= nacc; ++k )
  1004. X            {
  1005. X            int accnum = accset[k];
  1006. X
  1007. X            ++j;
  1008. X
  1009. X            if ( variable_trailing_context_rules &&
  1010. X             ! (accnum & YY_TRAILING_HEAD_MASK) &&
  1011. X             accnum > 0 &&
  1012. X             rule_type[accnum] == RULE_VARIABLE )
  1013. X            {
  1014. X            /* special hack to flag accepting number as part
  1015. X             * of trailing context rule
  1016. X             */
  1017. X            accnum |= YY_TRAILING_MASK;
  1018. X            }
  1019. X
  1020. X            mkdata( accnum );
  1021. X
  1022. X            if ( trace )
  1023. X            {
  1024. X            fprintf( stderr, "[%d]", accset[k] );
  1025. X
  1026. X            if ( k < nacc )
  1027. X                fputs( ", ", stderr );
  1028. X            else
  1029. X                putc( '\n', stderr );
  1030. X            }
  1031. X            }
  1032. X        }
  1033. X        }
  1034. X
  1035. X    /* add accepting number for the "jam" state */
  1036. X    acc_array[i] = j;
  1037. X
  1038. X    dataend();
  1039. X    }
  1040. X
  1041. X    else
  1042. X    {
  1043. X    dfaacc[end_of_buffer_state].dfaacc_state = end_of_buffer_action;
  1044. X
  1045. X    for ( i = 1; i <= lastdfa; ++i )
  1046. X        acc_array[i] = dfaacc[i].dfaacc_state;
  1047. X
  1048. X    /* add accepting number for jam state */
  1049. X    acc_array[i] = 0;
  1050. X    }
  1051. X
  1052. X    /* spit out "yy_accept" array.  If we're doing "reject", it'll be pointers
  1053. X     * into the "yy_acclist" array.  Otherwise it's actual accepting numbers.
  1054. X     * In either case, we just dump the numbers.
  1055. X     */
  1056. X
  1057. X    /* "lastdfa + 2" is the size of "yy_accept"; includes room for C arrays
  1058. X     * beginning at 0 and for "jam" state
  1059. X     */
  1060. X    k = lastdfa + 2;
  1061. X
  1062. X    if ( reject )
  1063. X    /* we put a "cap" on the table associating lists of accepting
  1064. X     * numbers with state numbers.  This is needed because we tell
  1065. X     * where the end of an accepting list is by looking at where
  1066. X     * the list for the next state starts.
  1067. X     */
  1068. X    ++k;
  1069. X
  1070. X    printf( C_short_decl, "yy_accept", k );
  1071. X
  1072. X    for ( i = 1; i <= lastdfa; ++i )
  1073. X    {
  1074. X    mkdata( acc_array[i] );
  1075. X
  1076. X    if ( ! reject && trace && acc_array[i] )
  1077. X        fprintf( stderr, "state # %d accepts: [%d]\n", i, acc_array[i] );
  1078. X    }
  1079. X
  1080. X    /* add entry for "jam" state */
  1081. X    mkdata( acc_array[i] );
  1082. X
  1083. X    if ( reject )
  1084. X    /* add "cap" for the list */
  1085. X    mkdata( acc_array[i] );
  1086. X
  1087. X    dataend();
  1088. X
  1089. X    if ( useecs )
  1090. X    genecs();
  1091. X
  1092. X    if ( usemecs )
  1093. X    {
  1094. X    /* write out meta-equivalence classes (used to index templates with) */
  1095. X
  1096. X    if ( trace )
  1097. X        fputs( "\n\nMeta-Equivalence Classes:\n", stderr );
  1098. X
  1099. X    printf( C_char_decl, "yy_meta", numecs + 1 );
  1100. X
  1101. X    for ( i = 1; i <= numecs; ++i )
  1102. X        {
  1103. X        if ( trace )
  1104. X        fprintf( stderr, "%d = %d\n", i, abs( tecbck[i] ) );
  1105. X
  1106. X        mkdata( abs( tecbck[i] ) );
  1107. X        }
  1108. X
  1109. X    dataend();
  1110. X    }
  1111. X
  1112. X    total_states = lastdfa + numtemps;
  1113. X
  1114. X    printf( tblend > MAX_SHORT ? C_long_decl : C_short_decl,
  1115. X        "yy_base", total_states + 1 );
  1116. X
  1117. X    for ( i = 1; i <= lastdfa; ++i )
  1118. X    {
  1119. X    register int d = def[i];
  1120. X
  1121. X    if ( base[i] == JAMSTATE )
  1122. X        base[i] = jambase;
  1123. X
  1124. X    if ( d == JAMSTATE )
  1125. X        def[i] = jamstate;
  1126. X
  1127. X    else if ( d < 0 )
  1128. X        {
  1129. X        /* template reference */
  1130. X        ++tmpuses;
  1131. X        def[i] = lastdfa - d + 1;
  1132. X        }
  1133. X
  1134. X    mkdata( base[i] );
  1135. X    }
  1136. X
  1137. X    /* generate jam state's base index */
  1138. X    mkdata( base[i] );
  1139. X
  1140. X    for ( ++i /* skip jam state */; i <= total_states; ++i )
  1141. X    {
  1142. X    mkdata( base[i] );
  1143. X    def[i] = jamstate;
  1144. X    }
  1145. X
  1146. X    dataend();
  1147. X
  1148. X    printf( tblend > MAX_SHORT ? C_long_decl : C_short_decl,
  1149. X        "yy_def", total_states + 1 );
  1150. X
  1151. X    for ( i = 1; i <= total_states; ++i )
  1152. X    mkdata( def[i] );
  1153. X
  1154. X    dataend();
  1155. X
  1156. X    printf( lastdfa > MAX_SHORT ? C_long_decl : C_short_decl,
  1157. X        "yy_nxt", tblend + 1 );
  1158. X
  1159. X    for ( i = 1; i <= tblend; ++i )
  1160. X    {
  1161. X    if ( nxt[i] == 0 || chk[i] == 0 )
  1162. X        nxt[i] = jamstate;    /* new state is the JAM state */
  1163. X
  1164. X    mkdata( nxt[i] );
  1165. X    }
  1166. X
  1167. X    dataend();
  1168. X
  1169. X    printf( lastdfa > MAX_SHORT ? C_long_decl : C_short_decl,
  1170. X        "yy_chk", tblend + 1 );
  1171. X
  1172. X    for ( i = 1; i <= tblend; ++i )
  1173. X    {
  1174. X    if ( chk[i] == 0 )
  1175. X        ++nummt;
  1176. X
  1177. X    mkdata( chk[i] );
  1178. X    }
  1179. X
  1180. X    dataend();
  1181. X    }
  1182. X
  1183. X
  1184. X/* write out a formatted string (with a secondary string argument) at the
  1185. X * current indentation level, adding a final newline
  1186. X */
  1187. X
  1188. Xvoid indent_put2s( fmt, arg )
  1189. Xchar fmt[], arg[];
  1190. X
  1191. X    {
  1192. X    do_indent();
  1193. X    printf( fmt, arg );
  1194. X    putchar( '\n' );
  1195. X    }
  1196. X
  1197. X
  1198. X/* write out a string at the current indentation level, adding a final
  1199. X * newline
  1200. X */
  1201. X
  1202. Xvoid indent_puts( str )
  1203. Xchar str[];
  1204. X
  1205. X    {
  1206. X    do_indent();
  1207. X    puts( str );
  1208. X    }
  1209. X
  1210. X
  1211. X/* make_tables - generate transition tables
  1212. X *
  1213. X * synopsis
  1214. X *     make_tables();
  1215. X *
  1216. X * Generates transition tables and finishes generating output file
  1217. X */
  1218. X
  1219. Xvoid make_tables()
  1220. X
  1221. X    {
  1222. X    register int i;
  1223. X    int did_eof_rule = false;
  1224. X
  1225. X    skelout();
  1226. X
  1227. X    /* first, take care of YY_DO_BEFORE_ACTION depending on yymore being used */
  1228. X    set_indent( 2 );
  1229. X
  1230. X    if ( yymore_used )
  1231. X    {
  1232. X    indent_puts( "yytext -= yy_more_len; \\" );
  1233. X    indent_puts( "yyleng = yy_cp - yytext; \\" );
  1234. X    }
  1235. X
  1236. X    else
  1237. X    indent_puts( "yyleng = yy_cp - yy_bp; \\" );
  1238. X
  1239. X    set_indent( 0 );
  1240. X    
  1241. X    skelout();
  1242. X
  1243. X
  1244. X    printf( "#define YY_END_OF_BUFFER %d\n", num_rules + 1 );
  1245. X
  1246. X    if ( fullspd )
  1247. X    { /* need to define the transet type as a size large
  1248. X       * enough to hold the biggest offset
  1249. X       */
  1250. X    int total_table_size = tblend + numecs + 1;
  1251. X    char *trans_offset_type =
  1252. X        total_table_size > MAX_SHORT ? "long" : "short";
  1253. X
  1254. X    set_indent( 0 );
  1255. X    indent_puts( "struct yy_trans_info" );
  1256. X    indent_up();
  1257. X        indent_puts( "{" );
  1258. X        indent_puts( "short yy_verify;" );
  1259. X
  1260. X        /* in cases where its sister yy_verify *is* a "yes, there is a
  1261. X     * transition", yy_nxt is the offset (in records) to the next state.
  1262. X     * In most cases where there is no transition, the value of yy_nxt
  1263. X     * is irrelevant.  If yy_nxt is the -1th  record of a state, though,
  1264. X     * then yy_nxt is the action number for that state
  1265. X         */
  1266. X
  1267. X        indent_put2s( "%s yy_nxt;", trans_offset_type );
  1268. X        indent_puts( "};" );
  1269. X    indent_down();
  1270. X
  1271. X    indent_puts( "typedef const struct yy_trans_info *yy_state_type;" );
  1272. X    }
  1273. X    
  1274. X    else
  1275. X    indent_puts( "typedef int yy_state_type;" );
  1276. X
  1277. X    if ( fullspd )
  1278. X    genctbl();
  1279. X
  1280. X    else if ( fulltbl )
  1281. X    genftbl();
  1282. X
  1283. X    else
  1284. X    gentabs();
  1285. X
  1286. X    if ( num_backtracking > 0 )
  1287. X    {
  1288. X    indent_puts( "static yy_state_type yy_last_accepting_state;" );
  1289. X    indent_puts( "static YY_CHAR *yy_last_accepting_cpos;\n" );
  1290. X    }
  1291. X
  1292. X    if ( nultrans )
  1293. X    {
  1294. X    printf( C_state_decl, "yy_NUL_trans", lastdfa + 1 );
  1295. X
  1296. X    for ( i = 1; i <= lastdfa; ++i )
  1297. X        {
  1298. X        if ( fullspd )
  1299. X        {
  1300. X        if ( nultrans )
  1301. X            printf( "    &yy_transition[%d],\n", base[i] );
  1302. X        else
  1303. X            printf( "    0,\n" );
  1304. X        }
  1305. X        
  1306. X        else
  1307. X        mkdata( nultrans[i] );
  1308. X        }
  1309. X
  1310. X    dataend();
  1311. X    }
  1312. X
  1313. X    if ( ddebug )
  1314. X    { /* spit out table mapping rules to line numbers */
  1315. X    indent_puts( "extern int yy_flex_debug;" );
  1316. X    indent_puts( "int yy_flex_debug = 1;\n" );
  1317. X
  1318. X    printf( C_short_decl, "yy_rule_linenum", num_rules );
  1319. X    for ( i = 1; i < num_rules; ++i )
  1320. X        mkdata( rule_linenum[i] );
  1321. X    dataend();
  1322. X    }
  1323. X
  1324. X    if ( reject )
  1325. X    {
  1326. X    /* declare state buffer variables */
  1327. X    puts(
  1328. X    "static yy_state_type yy_state_buf[YY_BUF_SIZE + 2], *yy_state_ptr;" );
  1329. X    puts( "static YY_CHAR *yy_full_match;" );
  1330. X    puts( "static int yy_lp;" );
  1331. X
  1332. X    if ( variable_trailing_context_rules )
  1333. X        {
  1334. X        puts( "static int yy_looking_for_trail_begin = 0;" );
  1335. X        puts( "static int yy_full_lp;" );
  1336. X        puts( "static int *yy_full_state;" );
  1337. X        printf( "#define YY_TRAILING_MASK 0x%x\n", YY_TRAILING_MASK );
  1338. X        printf( "#define YY_TRAILING_HEAD_MASK 0x%x\n",
  1339. X            YY_TRAILING_HEAD_MASK );
  1340. X        }
  1341. X
  1342. X    puts( "#define REJECT \\" );
  1343. X        puts( "{ \\" );
  1344. X        puts(
  1345. X    "*yy_cp = yy_hold_char; /* undo effects of setting up yytext */ \\" );
  1346. X        puts(
  1347. X        "yy_cp = yy_full_match; /* restore poss. backed-over text */ \\" );
  1348. X
  1349. X    if ( variable_trailing_context_rules )
  1350. X        {
  1351. X        puts( "yy_lp = yy_full_lp; /* restore orig. accepting pos. */ \\" );
  1352. X        puts(
  1353. X        "yy_state_ptr = yy_full_state; /* restore orig. state */ \\" );
  1354. X        puts(
  1355. X        "yy_current_state = *yy_state_ptr; /* restore curr. state */ \\" );
  1356. X        }
  1357. X
  1358. X        puts( "++yy_lp; \\" );
  1359. X        puts( "goto find_rule; \\" );
  1360. X        puts( "}" );
  1361. X    }
  1362. X    
  1363. X    else
  1364. X    {
  1365. X    puts( "/* the intent behind this definition is that it'll catch" );
  1366. X    puts( " * any uses of REJECT which flex missed" );
  1367. X    puts( " */" );
  1368. X    puts( "#define REJECT reject_used_but_not_detected" );
  1369. X    }
  1370. X    
  1371. X    if ( yymore_used )
  1372. X    {
  1373. X    indent_puts( "static int yy_more_flag = 0;" );
  1374. X    indent_puts( "static int yy_doing_yy_more = 0;" );
  1375. X    indent_puts( "static int yy_more_len = 0;" );
  1376. X    indent_puts(
  1377. X        "#define yymore() { yy_more_flag = 1; }" );
  1378. X    indent_puts(
  1379. X        "#define YY_MORE_ADJ (yy_doing_yy_more ? yy_more_len : 0)" );
  1380. X    }
  1381. X
  1382. X    else
  1383. X    {
  1384. X    indent_puts( "#define yymore() yymore_used_but_not_detected" );
  1385. X    indent_puts( "#define YY_MORE_ADJ 0" );
  1386. X    }
  1387. X
  1388. X    skelout();
  1389. X
  1390. X    if ( ferror( temp_action_file ) )
  1391. X    flexfatal( "error occurred when writing temporary action file" );
  1392. X
  1393. X    else if ( fclose( temp_action_file ) )
  1394. X    flexfatal( "error occurred when closing temporary action file" );
  1395. X
  1396. X    temp_action_file = fopen( action_file_name, "r" );
  1397. X
  1398. X    if ( temp_action_file == NULL )
  1399. X    flexfatal( "could not re-open temporary action file" );
  1400. X
  1401. X    /* copy prolog from action_file to output file */
  1402. X    action_out();
  1403. X
  1404. X    skelout();
  1405. X
  1406. X    set_indent( 2 );
  1407. X
  1408. X    if ( yymore_used )
  1409. X    {
  1410. X    indent_puts( "yy_more_len = 0;" );
  1411. X    indent_puts( "yy_doing_yy_more = yy_more_flag;" );
  1412. X    indent_puts( "if ( yy_doing_yy_more )" );
  1413. X    indent_up();
  1414. X    indent_puts( "{" );
  1415. X    indent_puts( "yy_more_len = yyleng;" );
  1416. X    indent_puts( "yy_more_flag = 0;" );
  1417. X    indent_puts( "}" );
  1418. X    indent_down();
  1419. X    }
  1420. X
  1421. X    skelout();
  1422. X
  1423. X    gen_start_state();
  1424. X
  1425. X    /* note, don't use any indentation */
  1426. X    puts( "yy_match:" );
  1427. X    gen_next_match();
  1428. X
  1429. X    skelout();
  1430. X    set_indent( 2 );
  1431. X    gen_find_action();
  1432. X
  1433. X    skelout();
  1434. X    if ( ddebug )
  1435. X    {
  1436. X    indent_puts( "if ( yy_flex_debug )" );
  1437. X    indent_up();
  1438. X
  1439. X    indent_puts( "{" );
  1440. X    indent_puts( "if ( yy_act == 0 )" );
  1441. X    indent_up();
  1442. X    indent_puts( "fprintf( stderr, \"--scanner backtracking\\n\" );" );
  1443. X    indent_down();
  1444. X
  1445. X    do_indent();
  1446. X    printf( "else if ( yy_act < %d )\n", num_rules );
  1447. X    indent_up();
  1448. X    indent_puts(
  1449. X    "fprintf( stderr, \"--accepting rule at line %d (\\\"%s\\\")\\n\"," );
  1450. X    indent_puts( "         yy_rule_linenum[yy_act], yytext );" );
  1451. X    indent_down();
  1452. X
  1453. X    do_indent();
  1454. X    printf( "else if ( yy_act == %d )\n", num_rules );
  1455. X    indent_up();
  1456. X    indent_puts(
  1457. X    "fprintf( stderr, \"--accepting default rule (\\\"%s\\\")\\n\"," );
  1458. X    indent_puts( "         yytext );" );
  1459. X    indent_down();
  1460. X
  1461. X    do_indent();
  1462. X    printf( "else if ( yy_act == %d )\n", num_rules + 1 );
  1463. X    indent_up();
  1464. X    indent_puts( "fprintf( stderr, \"--(end of buffer or a NUL)\\n\" );" );
  1465. X    indent_down();
  1466. X
  1467. X    do_indent();
  1468. X    printf( "else\n" );
  1469. X    indent_up();
  1470. X    indent_puts( "fprintf( stderr, \"--EOF\\n\" );" );
  1471. X    indent_down();
  1472. X
  1473. X    indent_puts( "}" );
  1474. X    indent_down();
  1475. X    }
  1476. X
  1477. X    /* copy actions from action_file to output file */
  1478. X    skelout();
  1479. X    indent_up();
  1480. X    gen_bt_action();
  1481. X    action_out();
  1482. X
  1483. X    /* generate cases for any missing EOF rules */
  1484. X    for ( i = 1; i <= lastsc; ++i )
  1485. X    if ( ! sceof[i] )
  1486. X        {
  1487. X        do_indent();
  1488. X        printf( "case YY_STATE_EOF(%s):\n", scname[i] );
  1489. X        did_eof_rule = true;
  1490. X        }
  1491. X    
  1492. X    if ( did_eof_rule )
  1493. X    {
  1494. X    indent_up();
  1495. X    indent_puts( "yyterminate();" );
  1496. X    indent_down();
  1497. X    }
  1498. X
  1499. X
  1500. X    /* generate code for handling NUL's, if needed */
  1501. X
  1502. X    /* first, deal with backtracking and setting up yy_cp if the scanner
  1503. X     * finds that it should JAM on the NUL
  1504. X     */
  1505. X    skelout();
  1506. X    set_indent( 7 );
  1507. X
  1508. X    if ( fullspd || fulltbl )
  1509. X    indent_puts( "yy_cp = yy_c_buf_p;" );
  1510. X    
  1511. X    else
  1512. X    { /* compressed table */
  1513. X    if ( ! reject && ! interactive )
  1514. X        {
  1515. X        /* do the guaranteed-needed backtrack to figure out the match */
  1516. X        indent_puts( "yy_cp = yy_last_accepting_cpos;" );
  1517. X        indent_puts( "yy_current_state = yy_last_accepting_state;" );
  1518. X        }
  1519. X    }
  1520. X
  1521. X
  1522. X    /* generate code for yy_get_previous_state() */
  1523. X    set_indent( 1 );
  1524. X    skelout();
  1525. X
  1526. X    if ( bol_needed )
  1527. X    indent_puts( "register YY_CHAR *yy_bp = yytext;\n" );
  1528. X
  1529. X    gen_start_state();
  1530. X
  1531. X    set_indent( 2 );
  1532. X    skelout();
  1533. X    gen_next_state( true );
  1534. X
  1535. X    set_indent( 1 );
  1536. X    skelout();
  1537. X    gen_NUL_trans();
  1538. X
  1539. X    skelout();
  1540. X
  1541. X    /* copy remainder of input to output */
  1542. X
  1543. X    line_directive_out( stdout );
  1544. X    (void) flexscan(); /* copy remainder of input to output */
  1545. X    }
  1546. END_OF_FILE
  1547.   if test 31594 -ne `wc -c <'gen.c'`; then
  1548.     echo shar: \"'gen.c'\" unpacked with wrong size!
  1549.   fi
  1550.   # end of 'gen.c'
  1551. fi
  1552. if test -f 'libmain.c' -a "${1}" != "-c" ; then 
  1553.   echo shar: Will not clobber existing file \"'libmain.c'\"
  1554. else
  1555.   echo shar: Extracting \"'libmain.c'\" \(256 characters\)
  1556.   sed "s/^X//" >'libmain.c' <<'END_OF_FILE'
  1557. X/* libmain - flex run-time support library "main" function */
  1558. X
  1559. X/* $Header: /usr/fsys/odin/a/vern/flex/RCS/libmain.c,v 1.2 90/05/26 16:50:08 vern Exp $ */
  1560. X
  1561. Xextern int yylex();
  1562. X
  1563. Xint main( argc, argv )
  1564. Xint argc;
  1565. Xchar *argv[];
  1566. X
  1567. X    {
  1568. X    return yylex();
  1569. X    }
  1570. END_OF_FILE
  1571.   if test 256 -ne `wc -c <'libmain.c'`; then
  1572.     echo shar: \"'libmain.c'\" unpacked with wrong size!
  1573.   fi
  1574.   # end of 'libmain.c'
  1575. fi
  1576. if test -f 'scan.l' -a "${1}" != "-c" ; then 
  1577.   echo shar: Will not clobber existing file \"'scan.l'\"
  1578. else
  1579.   echo shar: Extracting \"'scan.l'\" \(12439 characters\)
  1580.   sed "s/^X//" >'scan.l' <<'END_OF_FILE'
  1581. X
  1582. X/* scan.l - scanner for flex input */
  1583. X
  1584. X%{
  1585. X/*-
  1586. X * Copyright (c) 1990 The Regents of the University of California.
  1587. X * All rights reserved.
  1588. X *
  1589. X * This code is derived from software contributed to Berkeley by
  1590. X * Vern Paxson.
  1591. X * 
  1592. X * The United States Government has rights in this work pursuant
  1593. X * to contract no. DE-AC03-76SF00098 between the United States
  1594. X * Department of Energy and the University of California.
  1595. X *
  1596. X * Redistribution and use in source and binary forms are permitted provided
  1597. X * that: (1) source distributions retain this entire copyright notice and
  1598. X * comment, and (2) distributions including binaries display the following
  1599. X * acknowledgement:  ``This product includes software developed by the
  1600. X * University of California, Berkeley and its contributors'' in the
  1601. X * documentation or other materials provided with the distribution and in
  1602. X * all advertising materials mentioning features or use of this software.
  1603. X * Neither the name of the University nor the names of its contributors may
  1604. X * be used to endorse or promote products derived from this software without
  1605. X * specific prior written permission.
  1606. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  1607. X * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  1608. X * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  1609. X */
  1610. X
  1611. X#ifndef lint
  1612. Xstatic char rcsid[] =
  1613. X    "@(#) $Header: /usr/fsys/odin/a/vern/flex/RCS/scan.l,v 2.9 90/06/27 23:48:34 vern Exp $ (LBL)";
  1614. X#endif
  1615. X
  1616. X#undef yywrap
  1617. X
  1618. X#include "flexdef.h"
  1619. X#include "parse.h"
  1620. X
  1621. X#define ACTION_ECHO fprintf( temp_action_file, "%s", yytext )
  1622. X#define MARK_END_OF_PROLOG fprintf( temp_action_file, "%%%% end of prolog\n" );
  1623. X
  1624. X#undef YY_DECL
  1625. X#define YY_DECL \
  1626. X    int flexscan()
  1627. X
  1628. X#define RETURNCHAR \
  1629. X    yylval = yytext[0]; \
  1630. X    return ( CHAR );
  1631. X
  1632. X#define RETURNNAME \
  1633. X    (void) strcpy( nmstr, (char *) yytext ); \
  1634. X    return ( NAME );
  1635. X
  1636. X#define PUT_BACK_STRING(str, start) \
  1637. X    for ( i = strlen( (char *) (str) ) - 1; i >= start; --i ) \
  1638. X        unput((str)[i])
  1639. X
  1640. X#define CHECK_REJECT(str) \
  1641. X    if ( all_upper( str ) ) \
  1642. X        reject = true;
  1643. X
  1644. X#define CHECK_YYMORE(str) \
  1645. X    if ( all_lower( str ) ) \
  1646. X        yymore_used = true;
  1647. X%}
  1648. X
  1649. X%x SECT2 SECT2PROLOG SECT3 CODEBLOCK PICKUPDEF SC CARETISBOL NUM QUOTE
  1650. X%x FIRSTCCL CCL ACTION RECOVER BRACEERROR C_COMMENT ACTION_COMMENT
  1651. X%x ACTION_STRING PERCENT_BRACE_ACTION USED_LIST CODEBLOCK_2 XLATION
  1652. X
  1653. XWS        [ \t\f]+
  1654. XOPTWS        [ \t\f]*
  1655. XNOT_WS        [^ \t\f\n]
  1656. X
  1657. XNAME        [a-z_][a-z_0-9-]*
  1658. XNOT_NAME    [^a-z_\n]+
  1659. X
  1660. XSCNAME        {NAME}
  1661. X
  1662. XESCSEQ        \\([^\n]|[0-9]{1,3}|x[0-9a-f]{1,2})
  1663. X
  1664. X%%
  1665. X    static int bracelevel, didadef;
  1666. X    int i, indented_code, checking_used, new_xlation;
  1667. X    int doing_codeblock = false;
  1668. X    Char nmdef[MAXLINE], myesc();
  1669. X
  1670. X^{WS}            indented_code = true; BEGIN(CODEBLOCK);
  1671. X^#.*\n            ++linenum; /* treat as a comment */
  1672. X^"/*"            ECHO; BEGIN(C_COMMENT);
  1673. X^"%s"{NAME}?        return ( SCDECL );
  1674. X^"%x"{NAME}?        return ( XSCDECL );
  1675. X^"%{".*\n        {
  1676. X            ++linenum;
  1677. X            line_directive_out( stdout );
  1678. X            indented_code = false;
  1679. X            BEGIN(CODEBLOCK);
  1680. X            }
  1681. X
  1682. X{WS}            return ( WHITESPACE );
  1683. X
  1684. X^"%%".*            {
  1685. X            sectnum = 2;
  1686. X            line_directive_out( stdout );
  1687. X            BEGIN(SECT2PROLOG);
  1688. X            return ( SECTEND );
  1689. X            }
  1690. X
  1691. X^"%used"        {
  1692. X    pinpoint_message( "warning - %%used/%%unused have been deprecated" );
  1693. X            checking_used = REALLY_USED; BEGIN(USED_LIST);
  1694. X            }
  1695. X^"%unused"        {
  1696. X            checking_used = REALLY_NOT_USED; BEGIN(USED_LIST);
  1697. X    pinpoint_message( "warning - %%used/%%unused have been deprecated" );
  1698. X            checking_used = REALLY_NOT_USED; BEGIN(USED_LIST);
  1699. X            }
  1700. X
  1701. X
  1702. X^"%"[aeknopt]" ".*\n    {
  1703. X#ifdef NOTDEF
  1704. X            fprintf( stderr,
  1705. X                 "old-style lex command at line %d ignored:\n\t%s",
  1706. X                 linenum, yytext );
  1707. X#endif
  1708. X            ++linenum;
  1709. X            }
  1710. X
  1711. X^"%"[cr]{OPTWS}        /* ignore old lex directive */
  1712. X
  1713. X%t{OPTWS}\n        {
  1714. X            ++linenum;
  1715. X            xlation =
  1716. X                (int *) malloc( sizeof( int ) * (unsigned) csize );
  1717. X
  1718. X            if ( ! xlation )
  1719. X                flexfatal(
  1720. X                "dynamic memory failure building %t table" );
  1721. X
  1722. X            for ( i = 0; i < csize; ++i )
  1723. X                xlation[i] = 0;
  1724. X
  1725. X            num_xlations = 0;
  1726. X
  1727. X            BEGIN(XLATION);
  1728. X            }
  1729. X
  1730. X^"%"[^sxanpekotcru{}]{OPTWS}    synerr( "unrecognized '%' directive" );
  1731. X
  1732. X^{NAME}            {
  1733. X            (void) strcpy( nmstr, (char *) yytext );
  1734. X            didadef = false;
  1735. X            BEGIN(PICKUPDEF);
  1736. X            }
  1737. X
  1738. X{SCNAME}        RETURNNAME;
  1739. X^{OPTWS}\n        ++linenum; /* allows blank lines in section 1 */
  1740. X{OPTWS}\n        ++linenum; return ( '\n' );
  1741. X.            synerr( "illegal character" ); BEGIN(RECOVER);
  1742. X
  1743. X
  1744. X<C_COMMENT>"*/"        ECHO; BEGIN(INITIAL);
  1745. X<C_COMMENT>"*/".*\n    ++linenum; ECHO; BEGIN(INITIAL);
  1746. X<C_COMMENT>[^*\n]+    ECHO;
  1747. X<C_COMMENT>"*"        ECHO;
  1748. X<C_COMMENT>\n        ++linenum; ECHO;
  1749. X
  1750. X
  1751. X<CODEBLOCK>^"%}".*\n    ++linenum; BEGIN(INITIAL);
  1752. X<CODEBLOCK>"reject"    ECHO; CHECK_REJECT(yytext);
  1753. X<CODEBLOCK>"yymore"    ECHO; CHECK_YYMORE(yytext);
  1754. X<CODEBLOCK>{NAME}|{NOT_NAME}|.    ECHO;
  1755. X<CODEBLOCK>\n        {
  1756. X            ++linenum;
  1757. X            ECHO;
  1758. X            if ( indented_code )
  1759. X                BEGIN(INITIAL);
  1760. X            }
  1761. X
  1762. X
  1763. X<PICKUPDEF>{WS}        /* separates name and definition */
  1764. X
  1765. X<PICKUPDEF>{NOT_WS}.*    {
  1766. X            (void) strcpy( (char *) nmdef, (char *) yytext );
  1767. X
  1768. X            for ( i = strlen( (char *) nmdef ) - 1;
  1769. X                  i >= 0 &&
  1770. X                  nmdef[i] == ' ' || nmdef[i] == '\t';
  1771. X                  --i )
  1772. X                ;
  1773. X
  1774. X            nmdef[i + 1] = '\0';
  1775. X
  1776. X                        ndinstal( nmstr, nmdef );
  1777. X            didadef = true;
  1778. X            }
  1779. X
  1780. X<PICKUPDEF>\n        {
  1781. X            if ( ! didadef )
  1782. X                synerr( "incomplete name definition" );
  1783. X            BEGIN(INITIAL);
  1784. X            ++linenum;
  1785. X            }
  1786. X
  1787. X<RECOVER>.*\n        ++linenum; BEGIN(INITIAL); RETURNNAME;
  1788. X
  1789. X
  1790. X<USED_LIST>\n        ++linenum; BEGIN(INITIAL);
  1791. X<USED_LIST>{WS}
  1792. X<USED_LIST>"reject"    {
  1793. X            if ( all_upper( yytext ) )
  1794. X                reject_really_used = checking_used;
  1795. X            else
  1796. X                synerr( "unrecognized %used/%unused construct" );
  1797. X            }
  1798. X<USED_LIST>"yymore"    {
  1799. X            if ( all_lower( yytext ) )
  1800. X                yymore_really_used = checking_used;
  1801. X            else
  1802. X                synerr( "unrecognized %used/%unused construct" );
  1803. X            }
  1804. X<USED_LIST>{NOT_WS}+    synerr( "unrecognized %used/%unused construct" );
  1805. X
  1806. X
  1807. X<XLATION>"%t"{OPTWS}\n    ++linenum; BEGIN(INITIAL);
  1808. X<XLATION>^{OPTWS}[0-9]+    ++num_xlations; new_xlation = true;
  1809. X<XLATION>^.        synerr( "bad row in translation table" );
  1810. X<XLATION>{WS}        /* ignore whitespace */
  1811. X
  1812. X<XLATION>{ESCSEQ}    {
  1813. X            xlation[myesc( yytext )] =
  1814. X                (new_xlation ? num_xlations : -num_xlations);
  1815. X            new_xlation = false;
  1816. X            }
  1817. X<XLATION>.        {
  1818. X            xlation[yytext[0]] =
  1819. X                (new_xlation ? num_xlations : -num_xlations);
  1820. X            new_xlation = false;
  1821. X            }
  1822. X
  1823. X<XLATION>\n        ++linenum;
  1824. X
  1825. X
  1826. X<SECT2PROLOG>.*\n/{NOT_WS}    {
  1827. X            ++linenum;
  1828. X            ACTION_ECHO;
  1829. X            MARK_END_OF_PROLOG;
  1830. X            BEGIN(SECT2);
  1831. X            }
  1832. X
  1833. X<SECT2PROLOG>.*\n    ++linenum; ACTION_ECHO;
  1834. X
  1835. X<SECT2PROLOG><<EOF>>    MARK_END_OF_PROLOG; yyterminate();
  1836. X
  1837. X<SECT2>^{OPTWS}\n    ++linenum; /* allow blank lines in section 2 */
  1838. X
  1839. X<SECT2>^({WS}|"%{")    {
  1840. X            indented_code = (yytext[0] != '%');
  1841. X            doing_codeblock = true;
  1842. X            bracelevel = 1;
  1843. X
  1844. X            if ( indented_code )
  1845. X                ACTION_ECHO;
  1846. X
  1847. X            BEGIN(CODEBLOCK_2);
  1848. X            }
  1849. X
  1850. X<SECT2>"<"        BEGIN(SC); return ( '<' );
  1851. X<SECT2>^"^"        return ( '^' );
  1852. X<SECT2>\"        BEGIN(QUOTE); return ( '"' );
  1853. X<SECT2>"{"/[0-9]        BEGIN(NUM); return ( '{' );
  1854. X<SECT2>"{"[^0-9\n][^}\n]*    BEGIN(BRACEERROR);
  1855. X<SECT2>"$"/[ \t\n]    return ( '$' );
  1856. X
  1857. X<SECT2>{WS}"%{"        {
  1858. X            bracelevel = 1;
  1859. X            BEGIN(PERCENT_BRACE_ACTION);
  1860. X            return ( '\n' );
  1861. X            }
  1862. X<SECT2>{WS}"|".*\n    continued_action = true; ++linenum; return ( '\n' );
  1863. X
  1864. X<SECT2>{WS}        {
  1865. X            /* this rule is separate from the one below because
  1866. X             * otherwise we get variable trailing context, so
  1867. X             * we can't build the scanner using -{f,F}
  1868. X             */
  1869. X            bracelevel = 0;
  1870. X            continued_action = false;
  1871. X            BEGIN(ACTION);
  1872. X            return ( '\n' );
  1873. X            }
  1874. X
  1875. X<SECT2>{OPTWS}/\n    {
  1876. X            bracelevel = 0;
  1877. X            continued_action = false;
  1878. X            BEGIN(ACTION);
  1879. X            return ( '\n' );
  1880. X            }
  1881. X
  1882. X<SECT2>^{OPTWS}\n    ++linenum; return ( '\n' );
  1883. X
  1884. X<SECT2>"<<EOF>>"    return ( EOF_OP );
  1885. X
  1886. X<SECT2>^"%%".*        {
  1887. X            sectnum = 3;
  1888. X            BEGIN(SECT3);
  1889. X            return ( EOF ); /* to stop the parser */
  1890. X            }
  1891. X
  1892. X<SECT2>"["([^\\\]\n]|{ESCSEQ})+"]"    {
  1893. X            int cclval;
  1894. X
  1895. X            (void) strcpy( nmstr, (char *) yytext );
  1896. X
  1897. X            /* check to see if we've already encountered this ccl */
  1898. X            if ( (cclval = ccllookup( (Char *) nmstr )) )
  1899. X                {
  1900. X                yylval = cclval;
  1901. X                ++cclreuse;
  1902. X                return ( PREVCCL );
  1903. X                }
  1904. X            else
  1905. X                {
  1906. X                /* we fudge a bit.  We know that this ccl will
  1907. X                 * soon be numbered as lastccl + 1 by cclinit
  1908. X                 */
  1909. X                cclinstal( (Char *) nmstr, lastccl + 1 );
  1910. X
  1911. X                /* push back everything but the leading bracket
  1912. X                 * so the ccl can be rescanned
  1913. X                 */
  1914. X                PUT_BACK_STRING((Char *) nmstr, 1);
  1915. X
  1916. X                BEGIN(FIRSTCCL);
  1917. X                return ( '[' );
  1918. X                }
  1919. X            }
  1920. X
  1921. X<SECT2>"{"{NAME}"}"    {
  1922. X            register Char *nmdefptr;
  1923. X            Char *ndlookup();
  1924. X
  1925. X            (void) strcpy( nmstr, (char *) yytext );
  1926. X            nmstr[yyleng - 1] = '\0';  /* chop trailing brace */
  1927. X
  1928. X            /* lookup from "nmstr + 1" to chop leading brace */
  1929. X            if ( ! (nmdefptr = ndlookup( nmstr + 1 )) )
  1930. X                synerr( "undefined {name}" );
  1931. X
  1932. X            else
  1933. X                { /* push back name surrounded by ()'s */
  1934. X                unput(')');
  1935. X                PUT_BACK_STRING(nmdefptr, 0);
  1936. X                unput('(');
  1937. X                }
  1938. X            }
  1939. X
  1940. X<SECT2>[/|*+?.()]    return ( yytext[0] );
  1941. X<SECT2>.        RETURNCHAR;
  1942. X<SECT2>\n        ++linenum; return ( '\n' );
  1943. X
  1944. X
  1945. X<SC>","            return ( ',' );
  1946. X<SC>">"            BEGIN(SECT2); return ( '>' );
  1947. X<SC>">"/"^"        BEGIN(CARETISBOL); return ( '>' );
  1948. X<SC>{SCNAME}        RETURNNAME;
  1949. X<SC>.            synerr( "bad start condition name" );
  1950. X
  1951. X<CARETISBOL>"^"        BEGIN(SECT2); return ( '^' );
  1952. X
  1953. X
  1954. X<QUOTE>[^"\n]        RETURNCHAR;
  1955. X<QUOTE>\"        BEGIN(SECT2); return ( '"' );
  1956. X
  1957. X<QUOTE>\n        {
  1958. X            synerr( "missing quote" );
  1959. X            BEGIN(SECT2);
  1960. X            ++linenum;
  1961. X            return ( '"' );
  1962. X            }
  1963. X
  1964. X
  1965. X<FIRSTCCL>"^"/[^-\n]    BEGIN(CCL); return ( '^' );
  1966. X<FIRSTCCL>"^"/-        return ( '^' );
  1967. X<FIRSTCCL>-        BEGIN(CCL); yylval = '-'; return ( CHAR );
  1968. X<FIRSTCCL>.        BEGIN(CCL); RETURNCHAR;
  1969. X
  1970. X<CCL>-/[^\]\n]        return ( '-' );
  1971. X<CCL>[^\]\n]        RETURNCHAR;
  1972. X<CCL>"]"        BEGIN(SECT2); return ( ']' );
  1973. X
  1974. X
  1975. X<NUM>[0-9]+        {
  1976. X            yylval = myctoi( yytext );
  1977. X            return ( NUMBER );
  1978. X            }
  1979. X
  1980. X<NUM>","            return ( ',' );
  1981. X<NUM>"}"            BEGIN(SECT2); return ( '}' );
  1982. X
  1983. X<NUM>.            {
  1984. X            synerr( "bad character inside {}'s" );
  1985. X            BEGIN(SECT2);
  1986. X            return ( '}' );
  1987. X            }
  1988. X
  1989. X<NUM>\n            {
  1990. X            synerr( "missing }" );
  1991. X            BEGIN(SECT2);
  1992. X            ++linenum;
  1993. X            return ( '}' );
  1994. X            }
  1995. X
  1996. X
  1997. X<BRACEERROR>"}"        synerr( "bad name in {}'s" ); BEGIN(SECT2);
  1998. X<BRACEERROR>\n        synerr( "missing }" ); ++linenum; BEGIN(SECT2);
  1999. X
  2000. X
  2001. X<PERCENT_BRACE_ACTION,CODEBLOCK_2>{OPTWS}"%}".*        bracelevel = 0;
  2002. X<PERCENT_BRACE_ACTION,CODEBLOCK_2,ACTION>"reject"    {
  2003. X            ACTION_ECHO;
  2004. X            CHECK_REJECT(yytext);
  2005. X            }
  2006. X<PERCENT_BRACE_ACTION,CODEBLOCK_2,ACTION>"yymore"    {
  2007. X            ACTION_ECHO;
  2008. X            CHECK_YYMORE(yytext);
  2009. X            }
  2010. X<PERCENT_BRACE_ACTION,CODEBLOCK_2>{NAME}|{NOT_NAME}|.    ACTION_ECHO;
  2011. X<PERCENT_BRACE_ACTION,CODEBLOCK_2>\n            {
  2012. X            ++linenum;
  2013. X            ACTION_ECHO;
  2014. X            if ( bracelevel == 0 ||
  2015. X                 (doing_codeblock && indented_code) )
  2016. X                {
  2017. X                if ( ! doing_codeblock )
  2018. X                fputs( "\tYY_BREAK\n", temp_action_file );
  2019. X                
  2020. X                doing_codeblock = false;
  2021. X                BEGIN(SECT2);
  2022. X                }
  2023. X            }
  2024. X
  2025. X
  2026. X    /* Reject and YYmore() are checked for above, in PERCENT_BRACE_ACTION */
  2027. X<ACTION>"{"        ACTION_ECHO; ++bracelevel;
  2028. X<ACTION>"}"        ACTION_ECHO; --bracelevel;
  2029. X<ACTION>[^a-z_{}"'/\n]+    ACTION_ECHO;
  2030. X<ACTION>{NAME}        ACTION_ECHO;
  2031. X<ACTION>"/*"        ACTION_ECHO; BEGIN(ACTION_COMMENT);
  2032. X<ACTION>"'"([^'\\\n]|\\.)*"'"    ACTION_ECHO; /* character constant */
  2033. X<ACTION>\"        ACTION_ECHO; BEGIN(ACTION_STRING);
  2034. X<ACTION>\n        {
  2035. X            ++linenum;
  2036. X            ACTION_ECHO;
  2037. X            if ( bracelevel == 0 )
  2038. X                {
  2039. X                fputs( "\tYY_BREAK\n", temp_action_file );
  2040. X                BEGIN(SECT2);
  2041. X                }
  2042. X            }
  2043. X<ACTION>.        ACTION_ECHO;
  2044. X
  2045. X<ACTION_COMMENT>"*/"    ACTION_ECHO; BEGIN(ACTION);
  2046. X<ACTION_COMMENT>[^*\n]+    ACTION_ECHO;
  2047. X<ACTION_COMMENT>"*"    ACTION_ECHO;
  2048. X<ACTION_COMMENT>\n    ++linenum; ACTION_ECHO;
  2049. X<ACTION_COMMENT>.    ACTION_ECHO;
  2050. X
  2051. X<ACTION_STRING>[^"\\\n]+    ACTION_ECHO;
  2052. X<ACTION_STRING>\\.    ACTION_ECHO;
  2053. X<ACTION_STRING>\n    ++linenum; ACTION_ECHO;
  2054. X<ACTION_STRING>\"    ACTION_ECHO; BEGIN(ACTION);
  2055. X<ACTION_STRING>.    ACTION_ECHO;
  2056. X
  2057. X<ACTION,ACTION_COMMENT,ACTION_STRING><<EOF>>    {
  2058. X            synerr( "EOF encountered inside an action" );
  2059. X            yyterminate();
  2060. X            }
  2061. X
  2062. X
  2063. X<SECT2,QUOTE,CCL>{ESCSEQ}    {
  2064. X            yylval = myesc( yytext );
  2065. X            return ( CHAR );
  2066. X            }
  2067. X
  2068. X<FIRSTCCL>{ESCSEQ}    {
  2069. X            yylval = myesc( yytext );
  2070. X            BEGIN(CCL);
  2071. X            return ( CHAR );
  2072. X            }
  2073. X
  2074. X
  2075. X<SECT3>.*(\n?)        ECHO;
  2076. X%%
  2077. X
  2078. X
  2079. Xint yywrap()
  2080. X
  2081. X    {
  2082. X    if ( --num_input_files > 0 )
  2083. X    {
  2084. X    set_input_file( *++input_files );
  2085. X    return ( 0 );
  2086. X    }
  2087. X
  2088. X    else
  2089. X    return ( 1 );
  2090. X    }
  2091. X
  2092. X
  2093. X/* set_input_file - open the given file (if NULL, stdin) for scanning */
  2094. X
  2095. Xvoid set_input_file( file )
  2096. Xchar *file;
  2097. X
  2098. X    {
  2099. X    if ( file )
  2100. X    {
  2101. X    infilename = file;
  2102. X    yyin = fopen( infilename, "r" );
  2103. X
  2104. X    if ( yyin == NULL )
  2105. X        lerrsf( "can't open %s", file );
  2106. X    }
  2107. X
  2108. X    else
  2109. X    {
  2110. X    yyin = stdin;
  2111. X    infilename = "<stdin>";
  2112. X    }
  2113. X    }
  2114. END_OF_FILE
  2115.   if test 12439 -ne `wc -c <'scan.l'`; then
  2116.     echo shar: \"'scan.l'\" unpacked with wrong size!
  2117.   fi
  2118.   # end of 'scan.l'
  2119. fi
  2120. echo shar: End of archive 1 \(of 10\).
  2121. cp /dev/null ark1isdone
  2122. MISSING=""
  2123. for I in 1 2 3 4 5 6 7 8 9 10 ; do
  2124.     if test ! -f ark${I}isdone ; then
  2125.     MISSING="${MISSING} ${I}"
  2126.     fi
  2127. done
  2128. if test "${MISSING}" = "" ; then
  2129.     echo You have unpacked all 10 archives.
  2130.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2131. else
  2132.     echo You still must unpack the following archives:
  2133.     echo "        " ${MISSING}
  2134. fi
  2135. exit 0
  2136. exit 0 # Just in case...
  2137.